package com.huat.sportmeetingmanagement.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.huat.sportmeetingmanagement.dao.PlayerDao;
import com.huat.sportmeetingmanagement.entity.Admin;
import com.huat.sportmeetingmanagement.entity.Player;
import com.huat.sportmeetingmanagement.service.PlayerService;
import com.huat.sportmeetingmanagement.utils.Md5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class PlayerServiceImpl implements PlayerService {
    @Autowired
    PlayerDao playerDao;
    @Override
    public Page<Player> getPlayers(Player player) {
        PageHelper.startPage(player.getPageNum(),player.getPageSize());//分页数据
        return playerDao.getPlayers(player);
    }

    @Override
    public Integer addPlayer(Player player) {
        return playerDao.addPlayer(player);
    }

    @Override
    public Integer updatePlayer(Player player) {
        return playerDao.updatePlayer(player);
    }

    @Override
    public Integer deletePlayer(String id) {
        return playerDao.deletePlayer(id);
    }

    @Override
    public boolean resetPassword(Admin admin) {
        admin.setPassword(Md5Utils.code(admin.getPassword()));
        Integer result = playerDao.resetPassword(admin);
        if (result==0)
            return false;
        else
            return true;
    }

    @Override
    public Player getPlayerById(Integer id) {
        return playerDao.getPlayerById(id);
    }

    @Override
    public Integer deletePlayers(String[] ids) {
        return playerDao.deletePlayers(ids);
    }


    @Override
    public boolean login(Admin admin) {
        admin.setPassword(Md5Utils.code(admin.getPassword()));
        List<Admin> list = playerDao.queryAdmin(admin);
        if(list.isEmpty())
            return false;
        else
            return true;
    }
}
